package com.lightsaber.trade.cloth.service.programme;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.core.service.HppBaseServiceImpl;
import com.lightsaber.trade.cloth.dao.programme.OfferingCampusDao;
import com.lightsaber.trade.cloth.entity.programme.BaseProgramme;
import com.lightsaber.trade.cloth.entity.programme.OfferingCampus;

/**
 * @author LiuJian
 * 
 */
@Service
@Transactional
public class OfferingCampusManager extends HppBaseServiceImpl<OfferingCampus, String> {

    @Autowired
    private OfferingCampusDao offeringCampusDao;

    @Override
    protected BaseDao<OfferingCampus, String> getDao() {
        return offeringCampusDao;
    }

    public List<OfferingCampus> findByProgramme(final BaseProgramme programme) {
        return offeringCampusDao.findByProgramme(programme);
    }

    public void batchSave(final List<OfferingCampus> results) {

        for (OfferingCampus offeringCampus : results) {

            OfferingCampus old = offeringCampusDao.get(offeringCampus.getId());

            old.setCampus(offeringCampus.getCampus());
            old.setOfferingUnit(offeringCampus.getOfferingUnit());
            old.setOperatingCampus(offeringCampus.getOperatingCampus());
            old.setOperatingUnit(offeringCampus.getOperatingUnit());

        }

    }

    public List<String> distinctOperatingCampus(final String discipline) {
        return offeringCampusDao.distinctOperatingCampusByDiscipline(discipline);
    }

    public List<String> distinctOperatingUnit(final String discipline, final String operatingCampus) {
        return offeringCampusDao.distinctOperatingUnitByDiscipline(discipline, operatingCampus);
    }

}
